﻿
@{
    ViewBag.Title = "TestLib";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}



<!--begin grid code-->


<section id="widget-grid" class="">
    <div class="row">
         <!--Operation-->
        <div class="heading-buttons">
            <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                <h1 class="page-title txt-color-blueDark"><i class=" fa fa-file-text "></i>
                    课程试题
                </h1>
                
                
                
               

                  
            </div>
          
                 
            <div style="clear: both;">
            </div>
        </div>
        <!--/Operation-->
        <!--Search-->
        <div class="filter-bar">
            <form id="formSearch">
                <div class="lbl glyphicons search" style="cursor: pointer;" data-bind="click: $root.search">
                    <i></i>筛选
                </div>

                <div>
                    
                        <input id='txtbSrICousreID' name='txtbSrICousreID' type='hidden'  class='input-mini' value="@ViewBag.CourseID" />
                </div>

                <div>
                    <label>标题：</label><div class='input-append'>
                        <input id='txtbSrSTitle' name='txtbSrSTitle' type='text' placeholder='标题' class='input-mini' style='width: 120px;' /></div>
                </div>
                <div>
                    <label>对应大纲位置：</label>
                    <select name="txtbSrSCharpter" id="txtbSrSCharpter" data-bind="event: { change: $root.myChange }">

                        <option value="">---请选择章---</option>
                        @foreach (var itemSel in ViewBag.Charpter)
                        {
                            <option value="@itemSel.SCaptailName" data-value="@itemSel.Id" >
                                @itemSel.SCaptailName</option> 
                        }

                    </select>
                    <select id="txtbSrITeaCatalog" name="txtbSrITeaCatalog" data-bind="options: arrayBindSesson,
                       optionsValue:'Id',
                       optionsText: 'SCaptailName',
                       optionsCaption: '---请选择节---'">
                    </select>
                </div>
                <div style="float: right">
                    <label>题型选择：</label>
                    <select id="IProblemType" name="IProblemType">
                        <option value="">请选择</option>
                        <option value="1">单项选择题</option>
                        <option value="2">多项选择</option>
                        <option value="3">判断题</option>
                    </select>
                </div>
                <div class="clearfix">
                </div>

            </form>
        </div>
        <!--/search-->
        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
            <div id="wid-id-0" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"><i class="fa fa-table"></i></span>
                    <h2>试题列表</h2>
                </header>
                <div style="margin-top: 35px;">
                    <div class="jarviswidget-editbox"></div>
                    <div class="widget-body no-padding">
                        <div role="grid" id="providerGrid" class="dataTables_wrapper form-inline">
                            <div class="table-responsive">

                                <div class="dt-wrapper" style="overflow-y: auto;">
                                    <table class="table table-striped table-bordered table-hover checkboxs">
                                        <!--table head-->
                                        <thead>
                                            <tr>
                                                <th style="width: 1%">
                                                    <input type="checkbox" value="0" />
                                                </th>
                                                <!-- ko foreach: headers -->
                                                <th class="left ">
                                                    <a href="#" data-bind="text: displayText@*, click: $root.sort*@" style="color: black"></a>
                                                    <i class="icon-circle-arrow-up" data-bind="    visible: value == $root.orderBy() && $root.isAsc()"></i>
                                                    <i class="icon-circle-arrow-down" data-bind="    visible: value == $root.orderBy() && !$root.isAsc()"></i>
                                                </th>
                                                <!-- /ko -->
                                                
                                              
                                            </tr>
                                        </thead>
                                        <!--/table head-->
                                        <!--table body(Provider list)-->
                                        <tbody data-bind="foreach: recordSet">
                                            <tr class="selectable" onclick="">
                                                <td class="center">
                                                    <input type="checkbox" name="userSelector" data-bind="value: Id" />
                                                    <input type="hidden" data-bind="value: Id, attr: { id: Id }" />
                                                </td>


                                                <td ><a href="#myModal" role="button" style="color:black;" 
                                data-toggle="modal" data-bind="text: STitle,click:$root.TestLibView"></a></td>
                                                <td class='center'><strong data-bind='text: SCharpter'></strong></td>

                                                <td class='center'><strong data-bind='text: IHardLevel'></strong></td>


                                      
                                            
                                            </tr>
                                        </tbody>
                                        <!--/table body( Provider list)-->

                                    </table>

                                </div>



                                <!-- 分页 -->
                                <ul class="pagination pagination-alt">
                                    <li>
                                        <a data-bind="click: firstPage"><i class="fa fa-fast-backward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: prevPage"><i class="fa  fa-backward  "></i></a>
                                    </li>
                                    <li>
                                        <a>
                                            <input id="toPage" type="text" data-bind="value: pageIndex, event: { change: $root.changePageIndex }" style="width: 25px;" />
                                            /共<span data-bind="html: totalPages"></span>页 
                                        </a>
                                    </li>
                                    <li>
                                        <a data-bind="click: nextPage"><i class="fa fa-forward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: lastPage"><i class="fa fa-fast-forward "></i></a>
                                    </li>
                                </ul>

                                <div class="dt-top-row total  ">
                                    当前记录共：<span data-bind="html: totalCount"></span>条
                                </div>
                                <!--end 分页-->
                            </div>

                            <!-- /分页 -->


                        </div>

                        <!-- /分页 -->




                    </div>
                </div>

            </div>




        </article>

    </div>
    <!--end row-->
</section>




   <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="SysUserMessageModalLabel" aria-hidden="true" >
    <div class="modal-header" style="background-color:white;">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>       
        <h3 class="center" id="myModalLabel">试题详细信息</h3>
    </div>
    <div class="modal-body" style="background-color:white;height:300px;">
        <label  data-bind="text:STitle"></label>
        <p data-bind="html:SContent"></p>
        <table class="table">
            <tbody id="SOptionName"></tbody>

        </table>
        <label style="margin-top:5px" class="font-md">答案：</label><label id="judgeid" class="font-md"></label><br />
        <label style="margin-top:5px" class="font-md">知识考点：</label><label data-bind="text:SPointers"  ></label><br />
        <label style="margin-top:5px" class="font-md">答案分析：</label><label data-bind="text:SAnalysis"  ></label>
    </div>
    <div class="modal-footer"  style="margin-top:0px">
        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
    </div>
</div>




<input id="HiddenCourseID" type="hidden" value="@ViewBag.CourseID">

<script type="text/javascript">


    var gdViewModel;
    $(function () {

        $("#HerfID").hide();
        $._messengerDefaults = {
            extraClasses: 'messenger-fixed messenger-theme-future messenger-on-bottom messenger-on-right'
        }; //默认提示位置;


        var options = {

            


            dialogId: "previewMessageModal", //添加对话框


            pageSize: 20, //分页大小
            hidId: $("#txtbID"),
            SaveUpdateBtn: $("#btnSaveOrUpdateModel"),
            frmElement: $("#formTestLib"),

            //节点数据
            NodeValue: ko.observable({

                Id: 0,
                ICousreId: 0,
                SCourseCode: '',
                IProblemType: 0,
                STitle: '',
                SContent: '',
                IStuOpen: 0,
                SAnswer: '',
                ITeaCatalog: 0,
                IHardLevel: 0,
                IDiffLevel: 0,
                SPointers: '',
                SKeyWords: '',
                SCharpter: '',
                SAnalysis: '',  //答案解析

            }),


            //用户列表Grid头部列名称
            headers: [




 { displayText: '标题', value: 'STitle', width: 'auto' },
 { displayText: '对应大纲位置', value: 'ITeaCatalog', width: 'auto' },
 { displayText: '难易度', value: 'IHardLevel', width: 'auto' },



            ],

            //默认的排序方式
            defaultOrderBy: "Id",
            //用户查询URL
            dataQueryUrlAccessor: function () {
                return "/api/Student/SearchOpenTestLib/";
            },

            
            dataNodeSelect: function (id) {
                
                return "/api/TestLibExt/GetPreviewData?id=" + id;
            },


			 initEd: function () {
			    //gird初始化的后置事件 信息

			},



        };

       

        gdViewModel = new gridViewModel(options);

        gdViewModel.HerfStr = ko.observable();
        //转换函数，把题型数字转换成对应的字符串   
        gdViewModel.ChangeProblemType = function (IProblemType) {
            switch (IProblemType) {
                case 1:
                    return "单项选择题";
                    break;
                case 2:
                    return "多项选择题";
                    break;
                case 3:
                    return "判断题";
                    break;
                default:
                    break;
            }
        }

        //查看试题的具体内容 answerid
        gdViewModel.TestLibView = function (item)
        {
            
            var testLibID = item.Id;
            var problemType;//试题的类型
            $.ajax({
                url: '/api/Student/ShowDetailTestLib?testLibId=' + testLibID,
                type: 'POST',
                success: function (result)
                {
                    if (result != null)
                    {
                        var Optionslist = new Array();
                        $("#SOptionName").empty();
                        $("#judgeid").empty();
                        gdViewModel.STitle(result.LibItem.STitle);  //试题的标题
                        gdViewModel.SContent(result.LibItem.SContent);//试题的内容
                        gdViewModel.SPointers(result.LibItem.SPointers);//试题的知识点  SAnalysis
                        gdViewModel.SAnalysis(result.LibItem.SAnalysis);//试题的知识点  SAnalysis

                        problemType = result.LibItem.IProblemType; //试题的试题类型  add by yzp 10.26

                        Optionslist = result.OptionList;  //选项的内容
                        if (problemType == 1 || problemType == 2) { //是选择题的时候，处理选项

                            var answeroptionlist = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');//最多只有8个选项
                            var tepid = 0;
                            $.each(Optionslist, function (n, value) {
                                value.SOptionName = answeroptionlist[tepid] + ' ' + value.SOptionName;
                                tepid++;
                            });
                        }
                        switch (problemType) {
                            case 1:
                            case 2:
                                $.each(Optionslist, function (n, value) {
                                    $("#SOptionName").append('<tr><td>' + value.SOptionName + '</td></tr>')
                                });
                                break;
                            case 3:
                                $.each(Optionslist, function (n, value) {
                                    if (value.IIsTrue == 1) {
                                        $("#judgeid").append( value.SOptionName)
                                    }
                                })
                                break;
                        }
                        
                        
                        
                        switch (problemType)
                        {
                           
                            case 1:
                            case 2:
                                var answers="" ;
                                $.each(Optionslist, function (n, value) {
                                    if (value.IIsTrue == 1) {
                                        
                                        var Strs = value.SOptionName;
                                        var substr = Strs.substring(0, 1);
                                        answers = answers + ' ' + substr;
                                        
                                    }
                                })
                                $("#judgeid").append(answers);
                                break;
                            case 3:
                                break;
                        }
                        
                        

                        
                    }

                }
            })
        }


        gdViewModel.STitle = ko.observable();  //试题的标题
        gdViewModel.SContent = ko.observable();  //试题的内容
        gdViewModel.SPointers = ko.observable();  //试题的知识点
        gdViewModel.SAnalysis = ko.observable();  //试题的答案分析

        //9/1;所在节的处理
        gdViewModel.chaptesr = ko.observableArray();


        //在被选章里面绑定节
        gdViewModel.arrayBindSesson = ko.observableArray();
        gdViewModel.selectedchapter = ko.observableArray();//当前被选中的章
        gdViewModel.myChange = function (a, b, c, d) {//改变所选章时移动

            gdViewModel.arrayBindSesson.removeAll();//移除绑定的节

            var selV = $("#txtbSrSCharpter").find("option:selected").attr("data-value");
            if (selV == null || selV == "")
                return;
            $.getJSON("/api/TestLibExt/GetSession?ID=" + selV, null, function (data) {
                $.each(data, function (m, n) {

                    gdViewModel.arrayBindSesson.push(n);

                });

            });
        };

        gdViewModel.init();
        ko.applyBindings(gdViewModel);



    });

</script>


<!--/end grid code-->
